import Vue from 'vue';
import App from './App';
// import  './common/iconfont.js'
import common from '@/utils/common.js'
import {
	store,
	mutations
} from '@/store/index.js'
import {
	request
} from '@/request/index.js';

Vue.config.productionTip = false;

var version = Number(Vue.version.split('.')[0])
console.log('version', version)
Vue.mixin({
	methods: {
		setData: function(obj, callback) {
			let that = this;
			let keys = [];
			let val, data;
			Object.keys(obj).forEach(function(key) {
				keys = key.split('.');
				val = obj[key];
				data = that.$data;
				keys.forEach(function(key2, index) {
					if (index + 1 == keys.length) {
						that.$set(data, key2, val);
					} else {
						if (!data[key2]) {
							that.$set(data, key2, {});
						}
					}
					data = data[key2];
				})
			});
			callback && callback();
		}
	}
});

App.mpType = 'app';

const app = new Vue({
	...App
});
app.$mount();

for (let key in common) {
	Vue.prototype['$' + key] = common[key];
}
Vue.prototype.$request = request;
Vue.prototype.$store = store;
Vue.prototype.$mutations = mutations;

// 让app的onLaunch先执行，主要是用来进行登录
Vue.prototype.$onLaunched = new Promise(resolve => {
	Vue.prototype.$isResolve = resolve;
})
